package com.hb.trade.server.project.archive.controller;


import com.hb.core.pojo.Attachments;
import com.hb.core.pojo.project.archive.dto.ArchiveCommonFileDTO;
import com.hb.core.pojo.project.archive.dto.ProjectArchiveFileDTO;
import com.hb.core.pojo.project.archive.entity.ProjectArchiveFile;
import com.hb.trade.server.project.archive.service.ProjectArchiveFileService;
import org.fzzn.core.model.msg.Message;
import org.fzzn.core.model.msg.ResponseDto;
import org.fzzn.core.util.MsgUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yuezheng
 * @since 2022-02-17
 */
@RestController
public class ProjectArchiveFileController {

    @Autowired
    private ProjectArchiveFileService projectArchiveFileService;

    /**
     * 查询归档中的所有文件信息
     *
     * @param projectArchiveFileDTO
     * @return
     */
    @PostMapping("/archive/file/info")
    public Message<Object> info(@RequestBody ProjectArchiveFileDTO projectArchiveFileDTO) {
        List<ArchiveCommonFileDTO> archiveFileList = projectArchiveFileService.getArchiveFileList(projectArchiveFileDTO);
        Message<List<ArchiveCommonFileDTO>> success = MsgUtil.success(archiveFileList);
        return MsgUtil.success(archiveFileList);
    }

    /**
     * 查询归档中所有文件对象
     *
     * @param projectArchiveFileDTO
     * @return
     */
    @PostMapping("/archive/file/section")
    public Message<Attachments> getAttachments (@RequestBody ProjectArchiveFileDTO projectArchiveFileDTO) {
        Attachments result = this.projectArchiveFileService.getAttachmentBySectionId(projectArchiveFileDTO);
        return MsgUtil.success(result);
    }

    /**
     * 添加文件类型
     *
     * @Param: projectArchiveFileVO
     * @return: Message<Boolean>
     * @Author: 岳争
     * @Date: 2022/2/17
     */
    @PostMapping("/archive/type/add")
    public Message<Boolean> addArchiveType(@RequestBody ProjectArchiveFile projectArchiveFile) {


        int insert = projectArchiveFileService.addArchiveType(projectArchiveFile);
        return MsgUtil.success(insert > 0);
    }

    /**
     * 添加文件
     *
     * @param projectArchiveFile
     * @return
     */
    @PostMapping("/archive/file/add")
    public Message<Boolean> addArchiveFile(@RequestBody ProjectArchiveFile projectArchiveFile) {
        int update = projectArchiveFileService.addArchiveFile(projectArchiveFile);
        return MsgUtil.success();
    }


    /**
     * 删除文件类型
     *
     * @Param: projectArchiveFileVO
     * @return: ResponseDto
     * @Author: 岳争
     * @Date: 2022/2/17
     */
    @PostMapping("/archive/file/delById")
    Message<Boolean> deleteArchiveFile(@RequestBody ProjectArchiveFileDTO projectArchiveFileDTO) {
        return MsgUtil.success(projectArchiveFileService.removeType(projectArchiveFileDTO) > 0);
    }

    /**
     * 删除单个文件
     *
     * @Param: projectArchiveDetailDTO
     * @return: ResponseDto
     * @Author: 岳争
     * @Date: 2022/2/17
     */
    @PostMapping("/archive/file/del")
    Message<Boolean> deleteByFileid(@RequestBody ProjectArchiveFileDTO projectArchiveDetailDTO) {
        int delete = projectArchiveFileService.removeFile(projectArchiveDetailDTO);
        return MsgUtil.success();
    }
}
